<template>
    
    <div>
        <h1>用户投资赎回</h1>
        <table class="table table-bordered">
            <tr>
                <td>项目名称</td>  
                <td>{{ state.I_Name }}</td>  
            </tr>
            <tr>
                <td>项目总金额</td>  
                <td>{{ state.I_Budget }}</td>  
            </tr>
            <tr>
                <td>用户已投金额</td>  
                <td>{{ state.UI_Money }}</td>  
            </tr>
            <tr>
                <td>用户赎回金额</td>  
                <td><input type="text" v-model="UIR_Money" />
                    </td>  
            </tr>
            <tr>
                <td></td>  
                <td><input type="button" value="确认赎回" @click="redeem"/></td>  
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import{reactive,ref,toRefs,onMounted} from 'vue'
import { useRoute } from 'vue-router'
import { useUserStore } from  '../../store/User'
import axios from 'axios'
import router from '@/router';
let data:any=reactive({
    state:{
        
    },
    UIR_Money:'',
})
let{state,UIR_Money} =toRefs(data)
let route = useRoute()
onMounted(()=>{
    fan();
})
const fan=()=>{
    axios.get('/api/Invest/GetUserUIIdRedeemInfo',{
            params:{
                UIId:route.query.id
            }
        })
        .then(res=>{
            console.log(res)
            state.value=res.data.data[0]
        })
        .catch(err=>{
            console.log(err)
        })  
}
const redeem=()=>{
    axios.post('/api/Invest/PostAddUserRedeem',{
            data:{
              UI_Id:route.query.id,
              UIR_Money:UIR_Money.value
            }
        })
        .then(res=>{
            console.log(res)
            if(res.data.data>0){
                alert('赎回成功')
                router.push('/main/userInvestRedeemList')
            }
           else if(res.data.data==-1){
                alert('用户赎回金额不能大于总金额')
                return;
            }else{
                alert('赎回失败')
                return;
            }
        })
        .catch(err=>{
            console.log(err)
        })  
}
</script>

<style>

</style>